package com.xiaomaoguai.grpc.client;

import com.xiaomaoguai.grpc.api.RPCDateRequest;
import com.xiaomaoguai.grpc.api.RPCDateResponse;
import com.xiaomaoguai.grpc.api.RPCDateServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

/**
 * @fileName: GRPCClient.java
 * @author: WeiHui
 * @date: 2018/5/22 18:44
 * @version: v1.0.0
 * @since JDK 1.7
 */
public class GRPCClient {

    private static final String host = "localhost";

    private static final int serverPort = 9999;

    public static void main(String[] args)  {

        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(host, serverPort).usePlaintext().build();

        try {
            RPCDateServiceGrpc.RPCDateServiceBlockingStub rpcDateService = RPCDateServiceGrpc.newBlockingStub(managedChannel);
            RPCDateRequest rpcDateRequest = RPCDateRequest
                    .newBuilder()
                    .setUserName("hansonwang99")
                    .build();
            RPCDateResponse rpcDateResponse = rpcDateService.getDate(rpcDateRequest);
            System.out.println(rpcDateResponse.getServerDate());
        } finally {
            managedChannel.shutdown();
        }
    }

}
